package com.example.Controller;

import com.baomidou.mybatisplus.plugins.Page;

import com.example.Service.OrderService;
import com.example.pojo.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService ordrService;

    @PostMapping
    public boolean save(@RequestBody OrderInfo orderInfo) {
        return ordrService.insert(orderInfo);
    }

    @PutMapping
    public boolean update(@RequestBody OrderInfo orderInfo) {
        return ordrService.insertOrUpdate(orderInfo);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Integer id) {
        return ordrService.deleteById(id);
    }

    @GetMapping("/{id}")
    public OrderInfo findById (@PathVariable Integer id) {
        return ordrService.selectById(id);
    }

    @GetMapping("/list")
    public Page<OrderInfo> findAll (Integer pageNo, Integer pageSize) {
        //Wrapper<User> wrapper = new EntityWrapper<>();
        //wrapper.eq("password", "3333");
        //List<User> userList = userService.selectList(wrapper);
        Page<OrderInfo> page = new Page<>(pageNo, pageSize);  //第一个参数是页号 第二个参数是每页的条数
        return ordrService.selectPage(page);
    }
}